/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import * as crypto from 'crypto';

export enum HashAlgorithm {
  MD5 = 'md5',
  SHA1 = 'sha1',
  SHA256 = 'sha256',
}

export class Hash {
  static getHash(algorithm = HashAlgorithm.MD5) {
    return crypto.createHash(algorithm);
  }

  static hash(value: any, algorithm = HashAlgorithm.MD5): string {
    return crypto.createHash(algorithm).update(value).digest('hex');
  }
}
